package com.example.bill.adapter;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import com.example.bill.fragment.AddBillFragment;
import com.example.bill.fragment.BillQueryPageFragment;

public class MainPageFragmentAdapter extends FragmentPagerAdapter {

    public MainPageFragmentAdapter(@NonNull FragmentManager fm) {
        super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
    }

    @NonNull
    @Override
    public Fragment getItem(int position) {
        switch (position){
            case 0:
                return new AddBillFragment();
            case 1:
                return BillQueryPageFragment.newInstance(null,null);
        }

        throw new IllegalArgumentException("越界");
    }

    @Override
    public int getCount() {
        return 2;

    }

    @Nullable
    @Override
    public CharSequence getPageTitle(int position) {
        switch (position){
            case 0: return "添加账单";
            case 1: return "记录";
        }
        throw new IllegalArgumentException("越界");
    }
}
